/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package page;
import dbase.*;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import model.*;
import javax.servlet.http.HttpSession;
/**
 *
 * @author uzan
 */
public class GoCari {
    HttpServletRequest request;

    public GoCari(HttpServletRequest request){
        this.request = request;
    }

    public String getPageApprove(){
        HttpSession session = request.getSession();
        if (session.getAttribute("username") != null) {
            String nrp = request.getParameter("nrp");
            //int id = Integer.parseInt(nrp);
            DBconnection dbConn = new DBconnection();
            List<keanggotaan> kendAng = new ArrayList<keanggotaan>();
            DBkeanggotaan dbKendAng = new DBkeanggotaan(dbConn.getConnection());

            try{
                kendAng = dbKendAng.getAnggotaJoinKendaraan(nrp);
            }catch(Exception ex){
                ex.printStackTrace();
            }finally{
                dbConn.closeConnection();
            }
            request.setAttribute("kendaraanData", kendAng);
            return "approve.jsp";
        }
        else{
            return "index.jsp";
        }
}

    public String Cari(){
        HttpSession session = request.getSession();
        if (session.getAttribute("username") != null) {
            String input = request.getParameter("kataKunci");
            DBconnection dbConn = new DBconnection();
            List<keanggotaan> kendAng = new ArrayList<keanggotaan>();
            DBcari dbCari = new DBcari(dbConn.getConnection());

            try{
                kendAng = dbCari.getCari(input,input);
            }catch(Exception ex){
                ex.printStackTrace();
            }finally{
                dbConn.closeConnection();
            }
            request.setAttribute("kendaraanData", kendAng);
            return "hasilCari.jsp";
        }else{
            return "index.jsp";
            }
    }
}